package com.jinzhi.jzapi.training.controller;

import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.ApiResult;
import com.jinzhi.jzapi.training.pojo.TerExpertsVo;
import com.jinzhi.jzweb.domain.CoursesDO;
import com.jinzhi.jzweb.domain.KnowledgePointsDO;
import com.jinzhi.jzweb.service.CoursesService;
import com.jinzhi.jzweb.service.ExpertsService;
import com.jinzhi.jzweb.service.KnowledgePointsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/jzApi/teacher")
public class ApiTeacherController extends BaseController {

    @Autowired
    private ExpertsService expertsService;
    @Autowired
    private CoursesService coursesService;
    @Autowired
    private KnowledgePointsService knowledgePointsService;

    /**
    * api小程序端-讲师详情查询接口
    *
    * @Description: 根据讲师的用户id，查询讲师信息并返回；参数：讲师用户id
    * @Param: [id]
    * @return: com.jinzhi.common.utils.ApiResult<?>
    * @Author: kl
    * @Date: 2020-04-23
    */
    @GetMapping("/selProDetail")
    @Log("api小程序端-讲师详情查询接口")
    @ApiOperation(value = "api小程序端-讲师详情查询接口", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @Transactional
    public ApiResult<?> selProDetail(String id) {
        if(StringUtils.isBlank(id)){
            return ApiResult.lack("");//缺少参数
        }
        TerExpertsVo terExpertsVo = expertsService.selByUserIdTer(Long.parseLong(id));
        Map map = new HashMap();
        map.put("name",terExpertsVo.getName());
        map.put("headPortrait",terExpertsVo.getHeadPortrait());
        map.put("experience",terExpertsVo.getExperience());

        KnowledgePointsDO knowledgePointsDO = knowledgePointsService.selectById(terExpertsVo.getKpointsId());
        if(knowledgePointsDO != null){
            map.put("kpointsName",knowledgePointsDO.getName());
        }else{
            map.put("kpointsName","");
        }

        List<CoursesDO> coursesDOS = coursesService.findByKv("user_id",Long.parseLong(id));
        map.put("courserList",coursesDOS);
        return ApiResult.success(map);
    }


}
